﻿/*
 *Copyright(C) 2024 by CometGamming All rights reserved.
 *Unity版本：2022.3.33f1 
 *作者:程一峰  
 *创建日期: 2024-10-10 
 *模块说明：FSM状态机部分
 *版本: 0.1.0
*/

using Sirenix.OdinInspector;
using System;
using Warfare.FSM;

namespace GameAIStudy
{
    /// <summary>
    /// 闲置节点
    /// </summary>
    [Serializable]
    public class FSMNodeAction_Idle : FSMNodeAction
    {
        public override string ActionName => "闲置/等待";

        [LabelText("闲置时间")]
        public float IdleTime = 1;

        /// <summary>
        /// 进入时间；
        /// </summary>
        private float m_StartTime;

        public override void OnEnter(I_FSMContext context, I_FSMActor actor)
        {
            base.OnEnter(context, actor);
            m_StartTime = actor.GetTime;
        }

        public override E_MachineState Update(float deltaTime)
        {
            var duration = m_Actor.GetTime - m_StartTime;
            if (duration > IdleTime)
                return E_MachineState.Sucess;
            return E_MachineState.Running;
        }
    }
}
